package likou;

import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

/**
 * @author: Tangxz
 * @email: 1171702529@qq.com
 * @cate: 2020/12/16 11:59
 */
public class _290 {
    public static void main(String[] args) {

    }
    public boolean wordPattern(String pattern, String s) {
        Map<Byte,String> map = new HashMap<>();
        String[] strings = s.intern().split(" ");
        if (pattern.length()!=strings.length){
            return false;
        }
        byte[] bytes = pattern.getBytes();
        for (int i=0;i<bytes.length;i++){
            if (!map.containsKey(bytes[i])){
                map.put(bytes[i],strings[i]);
            }else {
                if (!map.get(bytes[i]).equals(strings[i])){
                    return false;
                }
            }
        }
        Set<String> set = new HashSet<>();
        for(Byte b:map.keySet()){
            set.add(map.get(b));
        }
        return set.size()==map.size();
    }
}
